﻿using StudySystem.MainLogic.Items;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StudySystem.MainLogic.FormControl
{
    public static class FormSubControl
    {
        /// <summary>
        /// 刷新课程
        /// </summary>
        /// <param name="formSub"></param>
        /// <param name="subjects"></param>
        public static void RenewSubject(FormSubject formSub, List<ClassSubject> subjects)
        {
            //删除原有的科目
            FormController.DeleteElement(formSub.GetFlow());
            ShowSubjects(formSub, subjects);
        }
        /// <summary>
        /// 显示所有学科
        /// </summary>
        /// <param name="formSub"></param>
        /// <param name="subjects"></param>
        public static void ShowSubjects(FormSubject formSub, List<ClassSubject> subjects)
        {
            FlowLayoutPanel f = formSub.GetFlow();
            foreach (ClassSubject s in subjects)
            {
                Subject subject = new Subject(s);
                f.Controls.Add(subject);
            }
        }

        /// <summary>
        /// 删除指定学科框
        /// </summary>
        /// <param name="fromSub"></param>
        /// <param name="s"></param>
        public static void DeleteASubject(FlowLayoutPanel flp,Subject s)
        {
            flp.Controls.Remove(s);
        }

        public static void ModifySubName(Subject s,string newName)
        {
            s.SetSubjectName(newName);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="formSub"></param>
        /// <returns></returns>
        public static List<ClassQuestion> RandomSelectQues(FormSubject formSub)
        {
            FlowLayoutPanel flp = formSub.GetFlow();
            List<ClassQuestion> ret = new List<ClassQuestion>();
            foreach (Subject s in flp.Controls)
            {
                ret.AddRange(s.Sub.GetQuestions(s.GetTrackBar().Value));
            }
            return ret;
        }

    }
}
